//
//  EJSShoppingCartListModel.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/3/16.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSShoppingCartListModel.h"

@implementation EJSShoppingCartListModel

- (NSString *)getArrayObjectClassNameForArrayName:(NSString *)arrayName{
    return @"EJSShoppingCartGoodsModel";
}

- (BOOL)wholeSelected{
    if(!self.list || self.list.count == 0){
        return NO;
    }
    for (EJSShoppingCartGoodsModel *model in self.list) {
        if(!model.selectState){
            return NO;
        }
    }
    return YES;
}

- (void)setWholeSelected:(BOOL)wholeSelected{
    for (EJSShoppingCartGoodsModel *model in self.list) {
        model.selectState = wholeSelected;
    }
}

- (NSArray *)selectedGoodsList{
    NSMutableArray *selectGoods = [NSMutableArray array];
    for (EJSShoppingCartGoodsModel *goodsModel in self.list) {
        if(goodsModel.selectState){
            [selectGoods addObject:goodsModel];
        }
    }
    return selectGoods;
}

- (CGFloat)selectedGoodsTotalPrice{
    CGFloat price = 0.0;
    for (EJSShoppingCartGoodsModel *goodsModel in self.list) {
        if(goodsModel.selectState){
            price += goodsModel.num.integerValue*goodsModel.price.floatValue;
        }
    }
    return price;
}

- (CGFloat)selectedGoodsTotalRebate{
    CGFloat price = 0.0;
    for (EJSShoppingCartGoodsModel *goodsModel in self.list) {
        if(goodsModel.selectState){
            price += goodsModel.num.integerValue*goodsModel.rebate.floatValue;
        }
    }
    return price;
}

- (BOOL)hasSelectedGoods{
    for (EJSShoppingCartGoodsModel *goodsModel in self.list) {
        if(goodsModel.selectState){
            return YES;
        }
    }
    return NO;
}


@end
